Skip to content

Close the screensaver when its idle cycle is cancelled - #14257

Open
airenare wants to merge 6 commits into
omacom:quattrofrom
airenare:fix/screensaver-survives-idle-cancel
Open

airenare wants to merge 6 commits into
omacom:quattrofrom
airenare:fix/screensaver-survives-idle-cancel

Conversation

@airenare

@airenare airenare commented Oct 4, 2026 •

Copy link
Copy Markdown

Fixes #14256 — the screensaver outlives its idle cycle.

Problem

cancelIdleCycle() in shell/plugins/services/idle/Service.qml stops the screensaver and lock timers and runs omarchy-system-wake, but never closes the screensaver terminal. The screensaver is started by omarchy-launch-screensaver through hypr_exec, so the cycle does not own that process.

Reproduced from the journal: an idle cycle launched the screensaver at 12:30:23, and Stay Awake was enabled at 12:30:24, cancelling the cycle. The window stayed up until the next keypress, and no lock ran.

Change

  • Each cycle records the screensaver windows it opens, from the Hyprland openwindow events, by address. A window started by hand is never recorded, because the launcher exits without opening a window when one is already running.
  • A cancelled cycle closes the windows it recorded, by address, with hl.dsp.window.close({ window = "address:0x…" }), the same form omarchy-hyprland-window-close-all uses.
  • If a cycle is cancelled while its launch is still running, late screensaver windows are closed as they open, capped at one per screen that the launch has not yet filled. Any screensaver beyond that cap is left alone. The late-close window clears three seconds after the launcher exits, and a new idle cycle clears it immediately.
  • A repeated open event for a window already tracked is ignored, so it can't use up a late-close slot.
  • Closes are queued, so one is never skipped while another runs.
  • Ownership, address handling, and the late-close cap live in IdleModel.js, with Node tests.
  • Idle status now reports the owned windows and the late-close state, for debugging.

Testing

Node tests: test/shell.d/idle-test.sh passes, covering address normalization, owned and unowned windows, closed windows, the generated close command, and the late-close cap.

Live, on two monitors, against the patched service:

  • Stay Awake during an idle cycle closes both windows. Pass.
  • A screensaver started by hand before a cycle survives the cycle's cancel on both monitors. Pass.
  • Cancel during launch leaves no window open. Pass, but this run cancelled after both windows had opened, so the late-close path was not exercised.

Not yet verified live: a late-close window that opens after a cancel during launch, and a hand-started screensaver launched right after that. Node tests cover the cap arithmetic, but not the timing.

Known limitations of the late-close path:

  • Monitor connects between cancel and launcher query. The late-close budget uses the larger of the launch-time and cancel-time screen counts. A monitor that connects after the cancel but before the launcher queries Hyprland can make it open one more window than the budget, which then stays open.
  • Manual screensaver maps before an owed window. The budget counts windows, not which process opened them. A hand-started screensaver that maps first in the late window takes the slot, is closed, and the owed window can survive. Matching windows to their launch by process ID doesn't work: each screensaver window's parent is Hyprland, not the launcher. An environment tag set by the launcher would identify them, but that needs a launcher change and is left for a follow-up.

Both need a hand-started screensaver or a monitor change within the same few seconds as a cancel. The failure is a screensaver staying up until a keypress.

Also not changed here: the launcher's "already running" check can see a screensaver process still closing after a close, and refuse a quick relaunch. It is a race in omarchy-launch-screensaver, separate from this change.

test/shell.d/runtime-smoke-test.sh fails one assertion (IPC handler registered once per screen). The same failure occurs on upstream/quattro without this change, so it appears to depend on the host's screen setup.

🤖 Generated with Claude Code

cancelIdleCycle stopped the timers but never closed the screensaver
terminal it had launched, so enabling Stay Awake mid-cycle left the
screensaver up with no lock pending.

Close the screensaver window when a cycle that launched it is cancelled.
@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds window-closing logic to the screensaver idle service.

No distinct new finding blocks merging this latest change.

Summary

The PR tracks screensaver windows opened during an idle cycle and closes them when the cycle is cancelled. The latest commit budgets late closes against the larger of the launch-time and cancellation-time screen counts to account for monitor changes.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Idle cycle launches screensaver] --> B[Record screensaver window addresses]
  B --> C[Cycle cancelled]
  C --> D[Close recorded addresses]
  C --> E[Calculate remaining late-close budget]
  E --> F[Close subsequent screensaver windows up to budget]
Loading

Reviews (6) · Last reviewed commit: "Budget late closes against the larger of..."

Comment thread shell/plugins/services/idle/Service.qml Resolved
Comment thread shell/plugins/services/idle/Service.qml Resolved
Comment thread test/shell.d/idle-test.sh Resolved
The previous change closed the screensaver with a pattern match, which
also killed a screensaver the user started by hand, and it missed a
window that opened after the cancel while the launcher was still
starting.

Track the windows each cycle opens and close them by address. A window
that opens after a cancel during an in-flight launch is closed on
arrival. Ownership and address handling live in IdleModel.js so the
cases are covered by Node tests.
@airenare

airenare commented Oct 4, 2026

Copy link
Copy Markdown
Author

Addressed the three review findings in 9ef46a6:

  1. Late screensaver escapes cancellation (P1): a cancel during an in-flight launch now sets a flag, and any screensaver window that opens afterwards is closed on arrival. The flag clears three seconds after the launcher exits, and a new idle cycle clears it right away.
  2. Manual screensaver closes unexpectedly (P1): the cycle only records windows that open during its own launch. A screensaver started by hand is never recorded, so cancelling leaves it alone. Closing is by address, not by pattern.
  3. Test misses cancellation behavior (P2): the ownership and address logic moved into IdleModel.js and is covered by Node tests (owned vs. unowned windows, closed windows, address normalization, generated close command). The text check is gone.

Still needs a live check on a real session (Stay Awake during an idle screensaver, a hand-started screensaver during idle, and multi-monitor). I'll run those and report back.

Comment thread shell/plugins/services/idle/Service.qml Resolved
A cancel during launch closed any screensaver window that opened in the
next few seconds, including one the user started by hand. Only one window
per screen can belong to the cancelled launch, so cap the late closes at
the number of screens the launch has not yet filled.

Also expose the owned windows and late-close state in idle status for
debugging.
A repeated openwindow event for a window the cycle already owned was counted
as a late window, spending a late-close slot on a window that was closing
anyway.
@airenare

airenare commented Oct 4, 2026

Copy link
Copy Markdown
Author

Pushed two commits for the latest findings:

  • b7bfddcf — late-window closes are now capped at the number of screens the cancelled launch has not yet filled. A hand-started screensaver that opens later is left alone. This is the P1 "Manual screensaver closes after cancellation" finding.
  • 837acdd2 — a repeated open event for a window already tracked is ignored, so it can't use up a late-close slot.

What's verified and what isn't:

  • Verified live, on two monitors: Stay Awake closes both cycle windows, and a hand-started screensaver survives a cancel.
  • Not yet verified live: the late-close path itself, meaning a window that opens after a cancel during launch. My last run cancelled after both windows had opened, so that path wasn't exercised. Node tests cover the cap arithmetic.

I've noted a separate race in omarchy-launch-screensaver: its "already running" check can see a process still closing and refuse a quick relaunch. It's outside this change; I haven't touched it. I'll keep working on the late-close live test.

Comment thread shell/plugins/services/idle/Service.qml Resolved
The budget used the screen count at cancel time, so a monitor dropping out
during the launch could shrink it to zero and leave a still-opening window
behind. Record the screen count when the launch starts instead.
@airenare

airenare commented Oct 4, 2026

Copy link
Copy Markdown
Author

Pushed 7c2a4e89 for the P1 "Pending screensaver can stay open" finding.

The late-close budget was sized from the screen count at cancel time, so a monitor dropping out mid-launch could shrink it to zero. The screen count is now recorded when the launch starts (launchScreenCount), and the budget is computed from that. Node tests and qmllint pass. This is still not verified live, same as the late-close path noted in the PR body.

Comment thread shell/plugins/services/idle/Service.qml Resolved
@aholbreich

Copy link
Copy Markdown
Contributor

I test-merged this onto current quattro@035ce29f.

The base source path confirms #14256: cancelIdleCycle() stops the lock timer and runs omarchy-system-wake, but neither path closes the independently launched screensaver window. With this PR merged, the cancellation contract closes owned windows and arms the late-window path.

Focused results:

  • test/shell.d/idle-test.sh: 39/39 passed
  • test/shell.d/screensaver-workspace-test.sh: 6/6 passed
  • git diff --check: passed

I also modeled the late-window sequence and reproduced both currently unresolved review concerns:

  1. If a monitor connects after launchScreenCount is sampled, the launcher can open more windows than the close budget, leaving one open.
  2. If a manually launched screensaver maps before an owed idle window, it consumes the close slot: the manual window is closed and the idle window can survive.

So the reported bug and ordinary cancellation fix are confirmed, but I would resolve or explicitly accept those two late-window ownership races before merging. I did not run a graphical test on the live desktop.

A monitor connecting mid-launch can make the launcher open for more screens
than were counted at launch, and a monitor dropping out shrinks the count at
cancel. Use the larger of the two so neither case leaves a window open.
@airenare

airenare commented Oct 5, 2026

Copy link
Copy Markdown
Author

Pushed b62c00eb for the P1 "New monitor escapes cancellation" finding.

The late-close budget now uses the larger of the screen count recorded at launch and the screen count at cancel. A monitor that connects after the launch starts is counted by the cancel-time count, and a monitor that drops out is still covered by the launch-time count. Node tests and qmllint pass. Still not verified live.

@airenare

airenare commented Oct 5, 2026

Copy link
Copy Markdown
Author

@greptileai could you re-review the latest commit, b62c00eb? It addresses the "New monitor escapes cancellation" finding by budgeting late closes against the larger of the launch-time and cancel-time screen counts. The previous commit, 7c2a4e89, addressed the monitor-dropout finding. Thanks.

@airenare

airenare commented Oct 5, 2026

Copy link
Copy Markdown
Author

Thanks @aholbreich for test-merging and for the two race write-ups. Both are now listed as known limitations in the PR body:

  1. Monitor connects between cancel and the launcher's query. The budget covers a monitor connected before the cancel (it uses the larger of the launch-time and cancel-time counts). A monitor connected after the cancel can still leave one extra window open.
  2. Manual screensaver maps before an owed window. The budget counts windows rather than tracking which process opened them, so the manual window can take the slot. I checked process-ID matching and it doesn't work: each screensaver window's parent is Hyprland, not the launcher. An environment tag set by the launcher would work but needs a launcher change, so I've left it for a follow-up.

Both need a hand-started screensaver or a monitor change within the same few seconds as a cancel. I'd rather state these openly than fix them with an unverified mechanism here. Your test results (39/39 idle, 6/6 workspace) match what I see on my side. Happy to adjust if you'd prefer the other trade-off.

@chessing234 chessing234 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head b62c00ebb6460b3a3a0fa70387805fa65fa1f2ac.

Reviewed window-address normalization, owned-window tracking, late-window budgeting, and the serialized close queue. The isolated idle model test passed. No additional reproducible defect found in those model paths. Ownership is inferred from launch timing rather than a launch token; the existing manual-launch overlap concern still needs a live integration reproduction.

@aholbreich

Copy link
Copy Markdown
Contributor

Thanks. The reported bug is the ordinary cancel path, and that's covered. The two leftover races need a monitor plug or a hand-started screensaver in the same few seconds as a cancel; listing them as known limitations is the right trade-off. I wouldn't block merge on an unverified launch tag.

@airenare

airenare commented Oct 6, 2026

Copy link
Copy Markdown
Author

Thanks @aholbreich, agreed on the trade-off.

One data point from a live run, in case it's useful for the merge decision: the manual-overlap race is currently hard to reach. A hand-started screensaver launched during an idle cycle was refused by omarchy-launch-screensaver's pgrep guard. The cycle's Ghostty processes were still alive, so the launcher exited 0 without opening a window. That guard is the one described in #10197. So the second race only becomes reachable once that guard is fixed. The launch-tag follow-up and #10197 are linked for that reason.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for the detailed write-up and the follow-ups on each review round. This pull request hasn't been classified yet, so it has no label and wasn't tested on a worker in this pass.

Classifying an item takes two models agreeing on what it is. I read it as a bug fix for #14256: cancelIdleCycle() in shell/plugins/services/idle/Service.qml on quattro stops the timers but never closes the screensaver terminal that omarchy-launch-screensaver started. The second model, Codex Medium, didn't run because the reviewer's daily limit was already used up, so there's no second answer yet. Without one, the class stays open, and verification waits until it's settled.

Next, it goes back in the queue to be classified with the second model, then verified on a worker built from the Omarchy ISO. There's nothing you need to do for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enabling Stay Awake mid-idle-cycle leaves the screensaver window running indefinitely

4 participants